package com.ssy.lingxi.member.merchant.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonManagedReference;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
import java.util.Set;

/**
 * 会员适用角色(sass)
 * @author whm
 * @version 2.0.0
 * @date 2022-03-10
 **/
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "fieldHandler"})
@Entity
@Table(schema = "public", name = "ms_mc_member_role_rule")
public class MemberRoleRuleDO implements Serializable {
    private static final long serialVersionUID = -9016587014959108029L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "role_rule_seq")
    @SequenceGenerator(sequenceName = "ms_mc_role_rule_seq", name = "role_rule_seq", allocationSize = 1)
    private Long id;

    /**
     * 当前会员id
     */
    @Column
    private Long memberId;

    /**
     * 当前名称
     */
    @Column
    private String memberName;

    /**
     * 多对多双向关联会员适用角色
     */
    @JsonManagedReference
    @ManyToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinTable(name = "ms_mc_member_role_rule_relation", joinColumns = {@JoinColumn(name = "member_id", referencedColumnName = "memberId")}, inverseJoinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")})
    private Set<RoleDO> memberRoleRule;

    /**
     * 多对多双向关联下属会员适用角色
     */
    @JsonManagedReference
    @ManyToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinTable(name = "ms_mc_sub_member_role_rule_relation", joinColumns = {@JoinColumn(name = "member_id", referencedColumnName = "memberId")}, inverseJoinColumns = {@JoinColumn(name = "role_id", referencedColumnName = "id")})
    private Set<RoleDO> subMemberRoleRule;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getMemberId() {
        return memberId;
    }

    public void setMemberId(Long memberId) {
        this.memberId = memberId;
    }

    public String getMemberName() {
        return memberName;
    }

    public void setMemberName(String memberName) {
        this.memberName = memberName;
    }

    public Set<RoleDO> getMemberRoleRule() {
        return memberRoleRule;
    }

    public void setMemberRoleRule(Set<RoleDO> memberRoleRule) {
        this.memberRoleRule = memberRoleRule;
    }

    public Set<RoleDO> getSubMemberRoleRule() {
        return subMemberRoleRule;
    }

    public void setSubMemberRoleRule(Set<RoleDO> subMemberRoleRule) {
        this.subMemberRoleRule = subMemberRoleRule;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MemberRoleRuleDO that = (MemberRoleRuleDO) o;
        return Objects.equals(id, that.id) && Objects.equals(memberId, that.memberId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, memberId);
    }
}
